const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const render = require('@koa/ejs');
const path = require('path');

const app = new Koa();
app.keys = ['ds2023'];

app.use(bodyParser());

// 请求出错日志
app.on('error', error => {
  console.error('请求出错: ', error);
});

app.use(require('koa-static')(path.join(__dirname, '/public')));

render(app, {
  root: path.join(__dirname, 'src/view'),
  layout: 'template',
  viewExt: 'html',
  cache: false,
  debug: false,
});

module.exports = app;
